class Solution {
public:
    TreeNode* invertTree_1(TreeNode* root) {
        if (!root) return root;
        queue<TreeNode *> q;
        q.push(root);
        while (!q.empty()) {
            int size = q.size();
            for (int i = 0; i < size; ++i) {
                TreeNode *node = q.front();
                q.pop();
                TreeNode *temp = node->left;
                node->left = node->right;
                node->right = temp;
                if (node->left) q.push(node->left);
                if (node->right) q.push(node->right);
            }
        }
        return root;
    }

    TreeNode* invertTree_2(TreeNode* root) {
        if (!root) return nullptr;
        if (!root->left && !root->right) {
            return root;
        } else {
            TreeNode *temp = root->left;
            root->left = invertTree(root->right);
            root->right = invertTree(temp);
            return root;
        }

    }
};